//
//  XMMessageInfo.m
//  tcpoctest
//
//  Created by gump on 11/6/12.
//  Copyright (c) 2012 gump. All rights reserved.
//

#import "XMMessageInfo.h"

@implementation XMMessageInfo

-(id)init
{
    self = [super init];
    if(self)
    {
        self.strmail = @"";
        self.mbAlreadayArgee = false;
        self.messageType = XMMT_CHAT;
        self.mindex = 0;
        self.strmsgid = @"";
        self.strtime = @"";
        self.badgeNum = 0;
    }
    return self;
}

-(NSString *)TurnTString
{
    NSArray * array = [self.strtime componentsSeparatedByString:@"/"];

    
    if ([array count] != 6) {
        return @"";
    }
    
    NSString * stryear = [array objectAtIndex:0];
    int year = [stryear intValue];
    
    NSString *time = @"";
    
    NSCalendar * calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    NSDateComponents * comps = [[NSDateComponents alloc] init];
    NSInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSWeekdayCalendarUnit |
    NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
    NSDate *curdate = [NSDate date];
    comps = [calendar components:unitFlags fromDate:curdate];
    int curyear=[comps year];
    
    if (curyear != year) {
        time = [NSString stringWithFormat:@"%d年",year];
    }
    else
    {
        stryear = [array objectAtIndex:1];
        year = [stryear intValue];
        
        time = [NSString stringWithFormat:@"%@%d月",time,year];
        
        stryear = [array objectAtIndex:2];
        year = [stryear intValue];
        
        time = [NSString stringWithFormat:@"%@%d日",time,year];
        
        stryear = [array objectAtIndex:3];
        year = [stryear intValue];
        
        if (year < 10) {
            time = [NSString stringWithFormat:@"%@0%d:",time,year];
        }
        else
        {
            time = [NSString stringWithFormat:@"%@%d:",time,year];
        }
        
        stryear = [array objectAtIndex:4];
        year = [stryear intValue];
        
        if (year < 10) {
            time = [NSString stringWithFormat:@"%@0%d:",time,year];
        }
        else
        {
            time = [NSString stringWithFormat:@"%@%d:",time,year];
        }
        
        stryear = [array objectAtIndex:5];
        year = [stryear intValue];
        
        if (year < 10) {
            time = [NSString stringWithFormat:@"%@0%d",time,year];
        }
        else
        {
            time = [NSString stringWithFormat:@"%@%d",time,year];
        }
    }
    
    return time;
}

@end
